<template>

  <el-container>
    <el-header>
      <Nav1></Nav1>
    </el-header>

    <el-main class="container">

      <el-card>
      <el-form :model="articleForm" ref="articleForm" label-position="top" @submit.prevent="submitForm">
        <el-form-item  >
          <div class="form-title">标题</div>
          <el-input class="my-custom-input" v-model="articleForm.title" ></el-input>
        </el-form-item>
        <el-form-item label>
          <div class="form-title">内容</div>
          <TinyMCN  class="editor" :value="articleForm.content" @input="(res)=> articleForm.content = res"></TinyMCN>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">发布文章</el-button>
        </el-form-item>
      </el-form>
      </el-card>

    </el-main>
  </el-container>
</template>

<script>
import {articleInsert} from "@/utils/api";
import TinyMCN from "@/components/TinyMCN/TinyMCN.vue";
import Nav1 from "@/components/nav/Nav1.vue";
export default {
  components:{
    Nav1,
    TinyMCN
  },
  data() {
    return {
      articleForm: {
        userId:'',
        title: '',
        content: '',
        createTime:''
      },
    };
  },
  methods: {
    submitForm() {

      this.articleForm.createTime=Date.now()/1000;
      alert(this.articleForm.create_time);
      articleInsert(this.articleForm)
          .then((response) => {
            // 处理成功的响应
            console.log('Article submitted successfully!', response);
          })
          .catch((error) => {
            // 处理错误
            console.error('Error submitting article:', error);
          });
    },
  },
  mounted() {
    this.articleForm.userId=sessionStorage.getItem('userId')
  }
};
</script>
<style  scoped>
.container {
  margin: 40px auto 0;
  padding: 10px 20px 50px 20px;
  min-width: 1300px;
  max-width: 1300px; /* 设置最大宽度 */
  box-sizing: border-box;
  flex-shrink: 0;
//display: flex; //justify-content: center; /* 水平居中 */ //align-items: center; /* 垂直居中  */
}
.form-title{
    font-size: 40px;
    font-family: 宋体, SimSun, STSong, sans-serif; /* 使用宋体字体，可以根据需要添加备选字体 */
    font-weight: bold; /* 加粗文本 */
    text-align: center; /* 文本水平居中 */
    height: auto; /* 这是默认值，使<div>的高度自适应内容 */
  margin:20px;
}

.my-custom-input {
  height: 50px; /* 设置高度为40像素 */
  font-size: 30px;
  width: 80%;
  margin-left: 80px;
}

.el-input__inner{
  height: 50px;
  margin:0 80px
}

.el-button{
  margin-left: 230px;
  width:800px;
  height: 40px;
  display: flex;
  justify-content: center;
}
</style>
